package com.youyi.yyfilepickerlibrary.core;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.lang.reflect.Field;

public abstract class BaseFileFragment extends Fragment {
    protected Bundle bundle = null;
    protected boolean isFirstLoad = true;
    protected boolean isOnDetach = false;
    protected boolean isPrepared = false;
    protected boolean isVisible;
    protected Activity mActivity = null;
    protected FragmentManager mFManager = null;
    protected Fragment mFragment = null;

    public abstract int getFragmentLayout();

    /* access modifiers changed from: protected */
    public abstract void lazyLoad();

    /* access modifiers changed from: protected */
    public void onInvisible() {
    }

    /* access modifiers changed from: protected */
    public void onRefresh(Message message) {
    }

    @Override // android.support.v4.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mActivity = getActivity();
        this.mFragment = this;
        this.isOnDetach = false;
        this.bundle = getArguments();
        this.mFManager = getChildFragmentManager();
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle2) {
        super.onCreateView(layoutInflater, viewGroup, bundle2);
        View inflate = layoutInflater.inflate(getFragmentLayout(), viewGroup, false);
        initUI(inflate);
        onVisible();
        return inflate;
    }

    public void setFirstLoad(boolean z) {
        this.isFirstLoad = z;
    }

    @Override // android.support.v4.app.Fragment
    public void setUserVisibleHint(boolean z) {
        super.setUserVisibleHint(z);
        if (getUserVisibleHint()) {
            this.isVisible = true;
            onVisible();
            return;
        }
        this.isVisible = false;
        onInvisible();
    }

    private void onVisible() {
        if (this.isFirstLoad && this.isVisible && this.isPrepared) {
            lazyLoad();
            this.isFirstLoad = false;
        }
    }

    /* access modifiers changed from: protected */
    public void initUI(View view) {
        this.isPrepared = true;
    }

    @Override // android.support.v4.app.Fragment
    public void onDetach() {
        super.onDetach();
        this.isOnDetach = true;
        try {
            Field declaredField = Fragment.class.getDeclaredField("mChildFragmentManager");
            declaredField.setAccessible(true);
            declaredField.set(this, null);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e2) {
            throw new RuntimeException(e2);
        }
    }
}
